package guan.dao;


import guan.bean.Book;

import java.util.List;

import net.sf.autodao.AutoDAO;
import net.sf.autodao.Dao;
import net.sf.autodao.Finder;
import net.sf.autodao.Limit;
import net.sf.autodao.Named;
import net.sf.autodao.Offset;

@AutoDAO
public interface BookDao extends Dao<Book, Long> {

	// this finder method uses index-based parameters and returns a single
	// object
	@Finder(query = "select b from Book b where title = ?")
	Book getByTitle(String title);

	// and this one uses named parameters and returns object list
	@Finder(query = "from Book where title = :title")
	List<Book> findWithTitleLike(@Named("title") String title);

	@Finder(query = "from Book b where b.title like :like order by id")
	List<Book> page(@Offset int pageNum, @Limit int pageSize,
			@Named("like") String like);

	@Finder(query = "select count(*) from Book b where b.title like :like order by id ")
	long countBooks(@Named("like") String like);

}
